<template>
    <div>
      <h1>房号增加</h1>
      <table class="table table-border">
        <tbody>
            <tr>
                <td align="right">房间号</td>
                <td>
                    <input type="text" v-model="info.HousenumName">
                </td>
            </tr>
            <tr>
                <td align="right">房型</td>
                <td>
                    <select v-model="info.HouseTypeId">
                        <option value="">请选择</option>
                        <option v-for="item in data2.list" :value="item.Id">{{item.HtName}}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">门店</td>
                <td>
                    <select v-model="info.ShopId">
                        <option value="">请选择</option>
                        <option v-for="item in data1.list" :value="item.Sid">{{item.ShopName}}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">房态</td>
                <td>
                    <select v-model="info.HouseNumState">
                        <option value="">请选择</option>
                        <option :value="1">空闲</option>
                        <option :value="2">已预约</option>
                        <option :value="3">已入住</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">房号状态</td>
                <td>
                    <input type="radio" name="state" v-model="info.State" :value="1">可用
                    <input type="radio" name="state" v-model="info.State" :value="0">不可用
                </td>
            </tr>
            <tr>
                <td align="right"></td>
                <td>
                   <input type="button" value="增加" class="btn btn-primary" @click="ok">
                </td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
//响应式数据
import {ref,reactive,onMounted} from 'vue';
import axios from 'axios';
import moment from 'moment';
//跳转
import {useRouter} from 'vue-router';
const router=useRouter();


let info:any=reactive({
  "HousenumName": '',
  "HouseTypeId":'',
  "ShopId": '',
  "HouseNumState":1,
  "State":1,
})
//============读取门店======================
//向后端传递的查询参数
let info1:any=reactive({
    pageindex:1,
    pagesize:100,
    ShopName:'',
    Time1:'',
    Time2:'',
})
//声明变量接收数据
let data1:any=reactive({
    list:[],
    totalCount:0,
    totalPage:0,
})
//生命周期函数
onMounted(()=>{
    getlist();
    gethouse();
})
//获取门店列表
const getlist=()=>{
    axios({
        url:'https://localhost:7193/api/Shop/GetShoplist',
        method:'get',
        params:info1,
    })
    .then(res=>{
        console.log(res);
        Object.assign(data1,res.data);
    })
}
//===============读取房型===================
let info2:any=reactive({
    pageindex:1,
    pagesize:100,
    HtName:'',
})

let data2:any=reactive({
    totalCount:0,
    totalPage:0,
    list:[],
})


const gethouse=()=>{
    axios({
        url:'https://localhost:7193/api/House/Gethouselist',
        method:'get',
        params:info2,
    })
    .then(res=>{
        console.log(res);
        Object.assign(data2,res.data);
    })
}
//===================添加====================

const ok=()=>{
  axios({
    url:'https://localhost:7193/api/House/HouseNumAdd',
    method:'post',
    data:info,
  })
  .then(res=>{
    console.log(res);
    if(res.data>0){
        alert('添加成功');
        router.push('/HouseNumberlist')
    }
    else{
        alert('添加失败');
    }
  })
}

</script>

<style scoped>

</style>